package project2.factory;

import project2.type.BulletType;
import project2.config.ImageConstants;
import project2.entity.bullet.Bullet;
import project2.entity.my.MyPlane;

public class BulletFactory {

    /**
     * 黄色单个子弹
     */
    public static Bullet createYellowBullet(MyPlane myPlane) {
        // 根据飞机的位置计算子弹的初始位置
        int planePosX = myPlane.getPosX();
        int planePosY = myPlane.getPosY();
        int bulletPosX = planePosX + myPlane.getWidth() / 2 - ImageConstants.YELLOW_BULLET_WIDTH / 2;
        int bulletPosY = planePosY + ImageConstants.YELLOW_BULLET_HEIGHT;

        Bullet b = new Bullet(myPlane.getPlayingPanel(), BulletType.YELLOW_BULLET);
        b.setPosX(bulletPosX);
        b.setPosY(bulletPosY);
        return b;
    }

    /**
     * 蓝色两个子弹
     */
    public static Bullet[] createBlueBullet(MyPlane myPlane) {
        // 左边子弹位置
        int planePosX = myPlane.getPosX();
        int planePosY = myPlane.getPosY();
        int bullet1PosX = planePosX + myPlane.getWidth() / 4 - ImageConstants.BLUE_BULLET_WIDTH / 2;
        int bullet1PosY = planePosY + ImageConstants.BLUE_BULLET_HEIGHT;

        // 左边子弹
        Bullet b1 = new Bullet(myPlane.getPlayingPanel(), BulletType.BLUE_BULLET);
        b1.setPosX(bullet1PosX);
        b1.setPosY(bullet1PosY);

        // 右边子弹位置
        int bullet2PosX = planePosX + myPlane.getWidth() / 4 * 3 - ImageConstants.BLUE_BULLET_WIDTH / 2;
        int bullet2PosY = planePosY + ImageConstants.BLUE_BULLET_HEIGHT;

        // 右边子弹
        Bullet b2 = new Bullet(myPlane.getPlayingPanel(), BulletType.BLUE_BULLET);
        b2.setPosX(bullet2PosX);
        b2.setPosY(bullet2PosY);

        Bullet[] bullets = new Bullet[2];
        bullets[0] = b1;
        bullets[1] = b2;
        return bullets;
    }
}
